from utils.game.hp_monitor import HPMonitor
import asyncio

class RolesMonitor:
    def __init__(self):
        self.hp_monitor = HPMonitor()
        self.last_hp = 0
        self.update_interval = 0.001  # 1毫秒更新间隔
        
    async def get_hp(self, window_pyauto):
        """获取实时血量"""
        try:
            # 获取HP区域截图
            hp_image = window_pyauto.get_hp_screenshot()
            if hp_image:
                # 使用像素计数法快速获取血量
                hp = await self.hp_monitor.get_hp(hp_image)
                self.last_hp = hp
                return hp
            return self.last_hp
        except Exception as e:
            print(f"获取血量失败: {e}")
            return self.last_hp 